package wodegua.d30_网络通信.d2_udp;


import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("------------服务端开始------------");
        DatagramSocket socket = new DatagramSocket(666);

        byte[] buffer = new byte[1024 * 64];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

        while (true) {
            socket.receive(packet);
            String s = new String(buffer,0,packet.getLength());
            System.out.println(s);
            System.out.println(packet.getAddress().getHostAddress());
            System.out.println(packet.getPort());
            System.out.println("----------------------------");
        }
    }
}
